#include <CUnit/Basic.h>
#include <consoleParser/consoleParser.h>
#include "testconsoleParser.h"
#include "common.h"
#include "debug.h"


void testparseConsoleInput(void)
{
	//test processArgs()
	int targc=3;
   char* targv[3];
   targv[0]="";
   targv[1]="-t";
   targv[2]="xxx.o";

   char* targv3[4];
      targv3[0]="";
      targv3[1]="-t";
      targv3[2]="-f";
      targv3[3]="xxx.o";

   char* tpArgFiles[20]; ///<File name
   char tpArg[20]; ///<List of commands
   	   // test with three arguments
      CU_ASSERT(parseConsoleInput(targc,targv,tpArgFiles,tpArg)==STATUS_SUCCESS);
      // test with a number of arguments greater than allowed
      CU_ASSERT(parseConsoleInput(21,targv,tpArgFiles,tpArg)==STATUS_ERROR);
      // test with two commands
      CU_ASSERT(parseConsoleInput(4,targv3,tpArgFiles,tpArg)==STATUS_SUCCESS);
}

void testparseConsoleInput2(void)
{
	///validateInput()
	   int targc=3;

   char* targv2[3];
   targv2[0]="";
   targv2[1]="-j";
   targv2[2]="xxx.o";
   char* targv3[4];
         targv3[0]="";
         targv3[1]="-t";
         targv3[2]="-f";
         targv3[3]="xxx.o";
    char* targv4[4];
         targv4[0]="";
         targv4[1]="-t";
         targv4[2]="test.o";
         targv4[3]="xxx.o";
    char* targv5[4];
    targv5[0]="";
    targv5[1]="-t";
    targv5[2]="-k";
    targv5[3]="xxx.o";
   char* tpArgFiles[20]; ///<File name
   char tpArg[20]; ///<List of commands

      // test with an invalid command
      CU_ASSERT_EQUAL(parseConsoleInput(targc,targv2,tpArgFiles,tpArg),STATUS_ERROR);
      // test with two commands
      CU_ASSERT(parseConsoleInput(4,targv3,tpArgFiles,tpArg)==STATUS_SUCCESS);
      // test with two input files
      CU_ASSERT(parseConsoleInput(4,targv4,tpArgFiles,tpArg)==STATUS_ERROR);
      // test with a valid and an invalid commmand.
      CU_ASSERT(parseConsoleInput(4,targv5,tpArgFiles,tpArg)==STATUS_ERROR);
}


/* The main() function for setting up and running the tests.
 * Returns a CUE_SUCCESS on successful running, another
 * CUnit error code on failure.
 */
int testconsoleParser()
{
	CU_pSuite pSuite = NULL;

	   /* initialize the CUnit test registry */
	   if (CUE_SUCCESS != CU_initialize_registry())
	      return CU_get_error();

	   /* add a suite to the registry */
	   pSuite = CU_add_suite("Suite_1", init_suite, clean_suite);
	   if (NULL == pSuite) {
	      CU_cleanup_registry();
	      return CU_get_error();
	   }

	   /* add the tests to the suite */
	   /* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
	   if ((NULL == CU_add_test(pSuite, "test of processArgs()", testparseConsoleInput)) ||
	       (NULL == CU_add_test(pSuite, "test of validateInput()", testparseConsoleInput2)))
	   {
	      CU_cleanup_registry();
	      return CU_get_error();
	   }

	   /* Run all tests using the CUnit Basic interface */
	   CU_basic_set_mode(CU_BRM_VERBOSE);
	   CU_basic_run_tests();
	   CU_cleanup_registry();
	   return CU_get_error();
}

